package com.tangkeyon.controller.current;

import com.github.pagehelper.PageInfo;
import com.tangkeyon.common.ResponseCode;
import com.tangkeyon.service.IProductService;
import com.tangkeyon.vo.ProductDetailVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: tangkeyon@gmail.com
 * @Date: 2019/6/9 17:57
 * @Version 1.0
 */
@Controller
@RequestMapping("product")
public class ProductController {
    @Autowired
    private IProductService iProductService;

    /**
     * @Description: 获取商品的详细信息
     * @param productId
     * @return
     */
    @RequestMapping("get_product_detail.do")
    @ResponseBody
    public ResponseCode<ProductDetailVO> getProductDetail(Integer productId){
        return iProductService.getDetail(productId);
    }


    /**
     * 根据类别，关键词查询商品并动态排序
     * @param keyword
     * @param categoryId
     * @param pageSize
     * @param pageNum
     * @param orderby
     * @return
     */
    @RequestMapping("list.do")
    @ResponseBody
    public ResponseCode<PageInfo> list(@RequestParam(value = "keyword",required = false) String keyword,
                                       @RequestParam(value = "categoryId",required = false) Integer categoryId,
                                       @RequestParam(value = "pageSize",defaultValue = "10")  Integer pageSize,
                                       @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                       @RequestParam(value = "orderby")  String orderby){
        return iProductService.searchProductListByCategoryIdOrName(keyword,categoryId,pageSize,pageNum,orderby);

    }
}
